<template>
  <!--模态窗 单行-->
  <transition
    name="custom-classes-transition"
    enter-active-class="animated fadeInDown"
    leave-active-class="animated fadeOutUp"
  >
    <div class="modal-ctrl-body" v-show="UpdateModalObj.isShow">
      <div class="modal-ctrl-main odd-row-ctrl">
        <div class="modal-title">
          <p>修改职位</p>
        </div>
        <div class="modal-ctrl-content">
          <div class="modal-row">
            <div class="modal-form-key f-l indispensable">
              职位名称：
            </div>
            <input type="text" v-model="AddData.position" class="modal-text f-l">
          </div>

          <div class="modal-row">
            <div class="modal-form-key f-l">
              排序：
            </div>
            <input type="text" maxlength="4" placeholder="最长4位字符" v-model="AddData.sort" class="modal-text f-l">
          </div>
        </div>
        <div class="btns text-r">
          <button type="button" class="btn btn-default" @click="close">取消</button>
          <button type="button" class="btn btn-info" @click="subBtn">确定</button>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
  export default {
    name: "UpdatePositionManage",
    props:["UpdateModalObj","UpdateData"],
    data(){
      return {
        AddData: {
          id: '',
          position: '' ,   // 职位
          sort:0  ,         // 排序
        }
      }
    },
    methods:{
      //提交
      subBtn(){
        //console.log(this.AddData);
        if( this.verifyForm.isNull(this.AddData.position) ){
          this.s_alert("职位不能为空！");
          return false;
        }else if( this.verifyForm.isNumber(this.AddData.sort) ){
          this.s_alert("排序字段只能为整数！");
          // alert("职位不能为空！");
          return false;
        }
        this.$axios.post(
          baseURL+"api/jp-HCZZ-AdminWeb-app-ms/policeposition/duty/update",this.AddData)
          .then(res => {
            //console.log(res);
            this.s_alert("修改成功！");
            this.close();
          })
          .catch(res => {
            this.s_alert("修改失败！");
            //console.log(res);
          })
      },

      //关闭弹窗
      close(){
        this.$emit("UpdateModalClose");
        this.clearData(); //关闭弹窗清除数据
      },
      //清除数据
      clearData(){
        this.AddData={
          id: '',
          position: '' ,   //职位
          sort: 0 ,         // 排序
        };
      }
    },// methods end
    watch:{
      UpdateData:{
        handler:function(val){
          if(val.id != ''){
            this.AddData = {
              id: val.id,
              position: val.position,
              sort: val.sort
            }
          }
        },
        deep: true
      }
    }
  }
</script>

<style scoped>

</style>
